package com.xxxy.dongyexuan.action;

import com.xxxy.dongyexuan.mapper.ICardMapper;
import com.xxxy.dongyexuan.mapper.ITechnologyMapper;
import com.xxxy.dongyexuan.po.Card;
import com.xxxy.dongyexuan.po.PageBean;
import com.xxxy.dongyexuan.po.Technology;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class TechnologyAction {

    @Autowired
    private ITechnologyMapper mapper;

    //分页查询
    @GetMapping("/technology-meirong/{pagenow}/{pagesize}")
    public PageBean findByMeiRongPage(@PathVariable("pagenow") int pagenow, @PathVariable("pagesize") int pagesize) {
        //开始条数
        int from = (pagenow - 1) * pagesize;
        //总条数
        int total = this.mapper.getcount(1);
        //计算总页数
        int pages = (total - 1) / pagesize + 1;
        List data = this.mapper.findByMeiRongPage(from, pagesize);
        PageBean pageBean = new PageBean();
        pageBean.setPages(pages);
        pageBean.setPagenow(pagenow);
        pageBean.setPagesize(pagesize);
        pageBean.setTotal(total);
        pageBean.setData(data);
        return pageBean;
    }

    @GetMapping("/technology-meifa/{pagenow}/{pagesize}")
    public PageBean findByMeiFaPage(@PathVariable("pagenow") int pagenow, @PathVariable("pagesize") int pagesize) {
        //开始条数
        int from = (pagenow - 1) * pagesize;
        //总条数
        int total = this.mapper.getcount(2);
        //计算总页数
        int pages = (total - 1) / pagesize + 1;
        List data = this.mapper.findByMeiFaPage(from, pagesize);
        PageBean pageBean = new PageBean();
        pageBean.setPages(pages);
        pageBean.setPagenow(pagenow);
        pageBean.setPagesize(pagesize);
        pageBean.setTotal(total);
        pageBean.setData(data);
        return pageBean;
    }


    //查询所有
    @GetMapping("/technology-meifa")
    public List<Technology> findAllMeiFa() {
        List<Technology> list = this.mapper.findTechnologyByMeIFa();
        return list;
    }

    //查询所有
    @GetMapping("/technology-list")
    public List<Technology> findAllTechnology() {
        List<Technology> list = this.mapper.findAll();
        return list;
    }

    //查询所有
    @GetMapping("/technology-meirong")
    public List<Technology> findAllMeiRong() {
        List<Technology> list = this.mapper.findTechnologyByMeIRong();
        return list;
    }


    //根据员工号查询
    @GetMapping("/technology-meifa/{tid}")
    public Technology findByIdmeifa(@PathVariable("tid") int tid) {
        Technology technology = this.mapper.findByIdmeifa(tid);
        return technology;
    }

    //根据员工号查询
    @GetMapping("/technology-meirong/{tid}")
    public Technology findByIdmeirong(@PathVariable("tid") int tid) {
        Technology technology = this.mapper.findByIdmeifa(tid);
        return technology;
    }

    //增加
    @PostMapping("/technology-meifa")
    public int savemeifa(Technology technology) {
        int result = this.mapper.savemeifa(technology);
        return result;
    }

    //修改
    @PutMapping("/technology-meifa")
    public int updatemeifa(Technology technology) {
        int result = this.mapper.mergemeifa(technology);
        return result;
    }

    //删除
    @DeleteMapping("/technology-meifa/{tid}")
    public int deletemeifa(@PathVariable("tid") int tid) {
        int result = this.mapper.deletemeifa(tid);
        return result;
    }

    //增加
    @PostMapping("/technology-meirong")
    public int savemeirong(Technology technology) {
        int result = this.mapper.savemeirong(technology);
        return result;
    }

    //修改
    @PutMapping("/technology-meirong")
    public int updatemeirong(Technology technology) {
        int result = this.mapper.mergemeirong(technology);
        return result;
    }

    //删除
    @DeleteMapping("/technology-meirong/{tid}")
    public int deletemeirong(@PathVariable("tid") int tid) {
        int result = this.mapper.deletemeirong(tid);
        return result;
    }
}